package com.newmacys.janrain;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import com.newmacys.bag.bean.BagBean;

public class JanrainWidgetManager extends DispatcherServlet {
	private static final long serialVersionUID = 1L;
       
    @Override
    protected void noHandlerFound(HttpServletRequest request,
    		HttpServletResponse response) throws Exception {
    	executeRequest(request, response);
    }

    private void executeRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
    	
    	WebApplicationContext context = getWebApplicationContext();
    	BagBean bag = ( BagBean ) context.getBean( "BagBean" );
		System.out.println( bag.getMessage() );

    	RequestDispatcher dispatcher = request.getRequestDispatcher("/janrainWidget.jsp");
		dispatcher.include(request, response);
		System.out.println("token="+request.getParameter("token"));
	}

}
